﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Manage/Views/Shared/Site.Master"Inherits="System.Web.Mvc.ViewPage<QianBuo.Lottery.Web.Areas.Manage.Models.CardsModels.IndexModel>" %>
<%@ Import Namespace="Code.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    点卡管理
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div id="card_div">
        <% Html.BeginForm("Index", "Cards", Url.Route(new { Model.Search })); %>
        <%=Html.HiddenFor(p => p.PageSize) %>
        <%=Html.ValidationMessage("Error") %>
        <table class="table" width="100%">
            <tr class="th">
                <th colspan="5" align="left">
                    &nbsp;&nbsp;&nbsp;&nbsp;查找条件
                </th>
            </tr>
            <tr>
                <td align="left">
                    卡号:
                    <%=Html.TextBoxFor(p => p.Search.Number, new { @class = "text100" }) %>
                    <%=Html.ValidationMessageFor(p => p.Search.Number) %>
                </td>
                <td align="left">
                    金额:
                    <%=Html.TextBoxFor(p => p.Search.Money, new { @class = "width70" })%>
                    <%=Html.ValidationMessageFor(p => p.Search.Money) %>
                </td>
                <td align="left">
                    添加日期:
                    <input type="text" id="Search_AddStartTime" name="Search.AddStartTime" class="width70"
                        onclick="WdatePicker()" value='<%=string.Format("{0:yyyy-MM-dd}", Model.Search.AddStartTime) %>' />
                    <%=Html.ValidationMessageFor(p => p.Search.AddStartTime) %>
                </td>
                <td align="left">
                    至:
                    <input type="text" id="Search_AddEndTime" name="Search.AddEndTime" class="width70"
                        onclick="WdatePicker()" value='<%=string.Format("{0:yyyy-MM-dd}", Model.Search.AddEndTime) %>' />
                    <%=Html.ValidationMessageFor(p => p.Search.AddEndTime) %>
                </td>
                <td rowspan="2">
                    <input type="submit" value="查找" />
                </td>
            </tr>
            <tr>
                <td align="left">
                    用户:
                    <%=Html.TextBoxFor(p => p.Search.UserName, new { @class = "text100" }) %>
                    <%=Html.ValidationMessageFor(p => p.Search.UserName) %>
                </td>
                <td align="left">
                    状态:<%=Html.DropDownListFor(p=>p.Search.State,Model.States) %>
                    <%=Html.ValidationMessageFor(p => p.Search.State) %>
                </td>
                <td align="left">
                    充值日期:
                    <input type="text" id="Search_UseStartTime" name="Search.UseStartTime" class="width70"
                        onclick="WdatePicker()" value='<%=string.Format("{0:yyyy-MM-dd}", Model.Search.UseStartTime) %>' />
                    <%=Html.ValidationMessageFor(p=>p.Search.UseStartTime) %>
                </td>
                <td align="left">
                    至:
                    <input type="text" id="Search_UseEndTime" name="Search.UseEndTime" class="width70"
                        onclick="WdatePicker()" value='<%=string.Format("{0:yyyy-MM-dd}", Model.Search.UseEndTime) %>' />
                    <%=Html.ValidationMessageFor(p=>p.Search.UseEndTime) %>
                </td>
            </tr>
            <tr>
                <td align="left">
                    添加:<%=Html.TextBoxFor(p => p.AddCount, new { @class="width100"})%> 张
                    <%=Html.ValidationMessageFor(p=>p.AddCount) %>
                </td>
                <td align="left">
                    面值:<%=Html.TextBoxFor(p => p.Money, new { @class = "width70" })%> 元
                    <%=Html.ValidationMessageFor(p=>p.Money) %>
                </td>
                <td>
                    <input type="submit" id="AddCard" onclick="return AddCardValid()" name="AddCard" value="添加点卡" />
                </td>
                <td align="left">
                    下载:<%=Html.DropDownListFor(p=>p.DownType,Model.DownTypes) %>
                    <%=Html.ValidationMessageFor(p=>p.DownType) %>
                </td>
                <td>
                    <input type="submit" id="DownLoad" onclick="return DownLoadValid()" name='DownLoad:<%=Model.Page %>' value="下载" />
                    <input type="submit" id="DelCard" onclick="return DelCardValid()" name='DelCard:<%=Model.Page %>' value="删除" />
                </td>
            </tr>
        </table>
        <p />
        <table class="table" width="100%">
            <tr class="th"><th>卡号</th><th>密码</th><th>面值</th><th>状态</th><th>添加日期</th><th>充值用户</th><th>充值时间</th><th style="padding:0px;"><input type="checkbox" onclick="Check(this)" /></th></tr>
            <% foreach (var item in Model.Cards) %>
            <% { %>
            <tr>
                <td class="number"><%=item.Number %></td>
                <td class="password"><%=item.Password %></td>
                <td><%=item.Money.ToString("C") %></td>
                <td><%=item.State.GetName() %></td>
                <td><%=item.AddTime.ToString("yyyy-MM-dd HH:mm") %></td>
                <td><%=item.UserName %></td>
                <td><%=string.Format("{0:yyyy-MM-dd HH:mm:ss}",item.UseTime) %></td>
                <td>
                    <% if (!item.UserID.HasValue) %>
                    <% { %>
                    <input type="checkbox" name="choose" id="choose" class=".choose" value='<%=item.Number %>' />
                    <% } %>
                </td>
            </tr>
            <% } %>
            <tr>
                <td colspan="8">
                    <% if (Model.SumCount > 0) %>
                    <% { %>
                    <%=Html.Pager(Model.Page.Value, Model.PageSize.Value, Model.SumCount, "Page", Url.Route(new { Model.Search }), "PageSize") %>
                    <% } %>
                    <% else %>
                    <% { %>
                    没有找到记录！
                    <% } %>
                </td>
            </tr>
        </table>
        <% Html.EndForm(); %>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="StyleAndScript" runat="server">
<style type="text/css">
    .width70{ width:70px;}
    .number{ font-family:宋体;}
</style>
<script type="text/javascript">
    function AddCardValid() {
        var count = $("#card_div #AddCount").val();
        var money = $("#card_div #Money").val();
        count = _ParseInt(count);
        money = _ParseDouble(money);
        if (count == null) {
            alert("请输入要添加数量");
        } else if (money == null) {
            alert("请输入生成的点卡的面值");
        } else {
            return true;
        }  
        return false;
    }
    function DownLoadValid() {
        var type = $("#card_div #DownType").val();
        type = _ParseInt(type);
        if (type == 3) {
            var choose = $("input:checked");
            if (choose.length < 1)   
                alert("请选择要下载的点卡");
            else
                return true; 
        } else {
            return true;
        }
        return false;
    }
    function DelCardValid() {
        var type = $("#card_div #DownType").val();
        type = _ParseInt(type);
        if (type == 3) {
            var choose = $("input:checked");
            if (choose.length < 1)
                alert("请选择删除点卡");
            else
                return confirm("确定要删除吗？删除后将不可恢复！");
        } else {
            return confirm("确定要删除吗？删除后将不可恢复！");
        }
        return false;
    }
    function Check(val) {
        $.each(document.getElementsByName("choose"), function (p, n) {
            n.checked = val.checked;
        });
    }
</script>
</asp:Content>
